/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.yiqi.lottery.feature.documentary.presenter;

import android.icu.lang.UScript;
import com.suozhang.framework.entity.bo.PageData;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.yiqi.lottery.common.widget.textview.MarqueeView;
import com.yiqi.lottery.entity.bo.HallBo;
import com.yiqi.lottery.entity.bo.HallUserBo;
import com.yiqi.lottery.entity.bo.OrderBo;
import com.yiqi.lottery.entity.bo.OrderDetailBo;
import com.yiqi.lottery.feature.documentary.contract.DocumentaryContract;
import com.yiqi.lottery.feature.documentary.contract.PersonContract;
import com.yiqi.lottery.feature.documentary.dependencies.hall.DaggerDocumentaryPresenterComponent;
import com.yiqi.lottery.feature.documentary.dependencies.home.DaggerFollowPresenterComponent;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 *      LIJUWEN
 * @email yiyayiyayaoljw@gmail.com
 * @date 2017/4/11 9:31
 */
public class PersonPresenter implements PersonContract.Presenter {

    private PersonContract.View mView;

    @Inject

    PersonContract.Model mModel;


    public PersonPresenter(PersonContract.View mView) {
        this.mView = mView;
        DaggerFollowPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void followUser(Integer userId) {
        if (userId == null) {
            return;
        }
        UserInfoBo userInfoBo = new UserInfoBo();
        userInfoBo.setUser_id(userId);
        mModel.followUser(userInfoBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(String s) {
                mView.showFollowSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
                mView.showFollowError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void unfollowUser(Integer userId) {
        if (userId == null) {
            return;
        }
        UserInfoBo userInfoBo = new UserInfoBo();
        userInfoBo.setUser_id(userId);
        mModel.unfollowUser(userInfoBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(String s) {
                mView.showFollowSuccess(s);
            }

            @Override
            public void onError(Throwable e) {
                mView.showFollowError(e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void followOrder(Integer orderId) {
        if (orderId == null) {
            return;
        }

        OrderBo orderBo = new OrderBo(orderId);
        mModel.followOrder(orderBo).compose(mView.bindToLife()).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(String s) {
                mView.showFollowOrderSuccess(s);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showFollowError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();

            }
        });
    }

    @Override
    public void getUserInfo(Integer userid) {

        mModel.getUserInfo(userid).compose(mView.bindToLife()).subscribe(new Observer<HallUserBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(HallUserBo s) {
                mView.showUserInfoSuccess(s);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showUserInfoError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();

            }
        });
    }

    @Override
    public void getGendanDetail(Integer orderid,int  type) {
        mModel.getGendanDetail(orderid,type).compose(mView.bindToLife()).subscribe(new Observer<OrderDetailBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(OrderDetailBo s) {
                mView.showGendanDetailSuccess(s);
                mView.dismissLoading();
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showUserInfoError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();

            }
        });
    }
}
